﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarketMS;
using Model;
using System.Data.Common;

namespace DAL
{
    public class GoodsDbhelper
    {
        static DBHelper db = null;
        public GoodsDbhelper()
        {
            db = new SqlServerDBHelper();
        }
        public List<GoodsInfo> QueryListByCode(string code)
        {
            List<GoodsInfo> list = new List<GoodsInfo>();
            string sql = "select * from GoodsInfo where goodscode like '%" + code + "%'";
            DbDataReader dr = db.GetReader(sql);

            while (dr.Read())
            {
                GoodsInfo g = new GoodsInfo();
                if (dr["Company"] != DBNull.Value)
                {
                    g.Company = Convert.ToInt32(dr["Company"]);

                }
                g.SalePrice = Convert.ToDouble(dr["SalePrice"]);
                g.GoodsCode = Convert.ToString(dr["GoodsCode"]);
                g.GoodsName = Convert.ToString(dr["GoodsName"]);
                g.GoodsState = Convert.ToInt32(dr["GoodsState"]);
                g.OriginPrice = Convert.ToDouble(dr["OriginPrice"]);

                if (dr["Stock"] != DBNull.Value)
                {
                    g.Stock = Convert.ToInt32(dr["Stock"]);
                }
                if (dr["Supplier"] != DBNull.Value)
                {
                    g.Supplier = Convert.ToInt32(dr["Supplier"]);
                }
                if (dr["Unit"] != DBNull.Value)
                {
                    g.Unit = Convert.ToString(dr["Unit"]);
                }
                list.Add(g);
            }
            dr.Close();
            db.Close();
            return list;
        }

    }
}
